import os
import re



from Base import GetYamlFile

YmlList = GetYamlFile.getYamlFile()
keywordsPath = YmlList["keywordsFile"]
PROJECT_ROOT = os.path.dirname(os.path.dirname(__file__))
REPORT_XLSX_DIR = os.path.join(PROJECT_ROOT, keywordsPath)

def getKeywords(keywords,regularKey):
    list1=[]
    with open(REPORT_XLSX_DIR, encoding='utf-8') as f:
        contents = f.readline()
        while contents:
            contents = contents.replace(" ", "")
            if contents.rfind(keywords) != -1:
                print(contents.rfind(keywords))
                contents = re.findall(regularKey, contents)
                if len(contents) != 0:
                    print(contents[0])
                    list1.append(contents[0])
                # print(contents[contents.rfind("uid")+8:contents.rfind("}]")])
            contents = f.readline()
        print(list1)
        list1 = set(list1)
        print(list1)
        list1 =list(list1)
        list1.reverse()
        print(list1)
        f.close()


if __name__ == '__main__':
    regularKey = r"uid\\\\\\\":(.+?)}]"
    # regularKey1 = "uid\\\\\\\":(.+?)}]"
    # print(regularKey)
    # print(regularKey1)
    getKeywords("uid", regularKey)